/**
 * @projectName: api-interface
 * @package: com.wangzz.apiinterface.controller
 * @className: NameController
 * @author: wangzz
 * @description: TODO
 * @date: 2024/3/10 20:15
 * @version: 1.0
 */

package com.wangzz.apiinterface.controller;

import com.wangzz.apiclientsdk.model.User;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: wangzz
 * @Description: TODO(一句话描述功能)
 * @DateTime: 2024/3/10 20:15
 **/

@RestController
@RequestMapping("/name")
public class NameController {

    @GetMapping("/get")
    public String getNameByGet(String name) {
        return "GET 你的名字是" + name;
    }

    @PostMapping("/post")
    public String getNameByPost(String name) {
        return "POST 你的名字是" + name;
    }

    @PostMapping("/user")
    public String getNameByPost(@RequestBody User user, HttpServletRequest request) {
        // 在网关中进行了校验
//        String accessKey = request.getHeader("accessKey");
//        String nonce = request.getHeader("nonce");
//        String timeStamp = request.getHeader("timeStamp");
//        String sign = request.getHeader("sign");
//        String body = URLDecoder.decode(request.getHeader("body"), StandardCharsets.UTF_8.name());
//
//        if (!accessKey.equals("wangzz")) {
//            throw new RuntimeException("无权限");
//        }
//
//        if (Long.parseLong(nonce) > 100000) {
//            throw new RuntimeException("无权限");
//        }
////        if (timeStamp){
////
////        }
//        String serverSign = SignUtil.getSign(body, "wangzz");
//        if (!serverSign.equals(sign)){
//            throw new RuntimeException("无权限");
//        }

        return "POST 用户名字是" + user.getUsername();
    }
}